// 全局类型
type user = struct {
	int id
	string username
	string password
}

// 全局变量(暂时不支持类型自动推导)
int id = 1
[user] list = []
{string:user} userof = {}

// 全局函数
fn register(string username, string password) {
	var (u, _) = try userof[username]
    if u.id > 0 {
        throw 'The user ' + username +' has already registered'
    }

	u = user {
		id = id,
		username = username,
		password = password
	}

	list.push(u)
	userof[username] = u
	id += 1
}

fn find(string username):user {
    var (u, _) = try userof[username]
	if u.id == 0 {
		throw 'user ' + username + ' notfound'
	}

	return u
}